import React, { Component } from "react";
import pubSub from "pubsub-js";


export default class Search extends Component {
  keyWord = React.createRef();
  render() {
    return (
      <section className="jumbotron">
        <h3 className="jumbotron-heading">Search Github Users</h3>
        <div>
          <input type="text"
            placeholder="enter the name you search"
          ref={this.keyWord}/>
          <button
            onClick={() => {
              const keyWord = this.keyWord.current.value.trim();
              if (keyWord.length > 0) {
                pubSub.publish("Search", keyWord);
              } else {
                alert("请输入内容");
              }
            }}
          >
            Search
          </button>
        </div>
      </section>
    );
  }
}
